/**
 * Created by XiMing on 2015/6/21.
 */
/**
 * Created by XiMing on 2015/6/21.
 */
var nodemailer = require('nodemailer');
var co = require('co'),
    request = require('request'),
    schedule = require("node-schedule"),
    cheerio  = require('cheerio'),
    db = require('./db');
var transporter = nodemailer.createTransport({
    service: '163',
    auth: {
        user: 'a1308118099@163.com',
        pass: 's807754634'
    }
});



var sendemail = function(title,link,id){
    var mailOptions = {
        from: '测试<807754634@qq.com>', // sender address
        to: 'ximing@yeanzhi.cn,2296261055@qq.com',// list of receivers
        subject: title, // Subject line
        html: '<a href="http://ssdut.dlut.edu.cn'+link+'"><p>'+title+'</p></a>'// plaintext body
    };
    transporter.sendMail(mailOptions, function(error, info){
        if(error){
            return console.log(error);
        }else{
            console.log('Message sent: ' + info.response);
            //db.zhouzhi.find({where:{id:id}}).then(function(p){
            //   p.send_email = 0;
            //   p.save().then(function(p){});
            //});
        }

    });
};
sendemail('a',"nihao",123);
//db.zhouzhi.findAll({where:{title:{ $like: '%研%'},send_email:1}}).then(function(p){
//    var len = p.length;
//    for(var i=0;i<len;i++){
//        (function(i){
//            sendemail(p[i].title,p[i].link,p[i].id);
//        }(i))
//    }
//});